package com.jh.user.repository;

import java.util.List;

import javax.persistence.LockModeType;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Lock;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.jh.user.pojo.UserAccount;

@Repository
public interface UserAccountRepository extends JpaRepository<UserAccount,String>,JpaSpecificationExecutor<UserAccount>{

	@Lock(value = LockModeType.PESSIMISTIC_WRITE)
	@Query("select account from  UserAccount account where account.userId=:userid")
	UserAccount findUserAccountByUseridLock(@Param("userid") long userid);
	
	
	@Query("select account from  UserAccount account where account.userId=:userid")
	UserAccount findUserAccountByUserid(@Param("userid") long userid);
	
	//根据userid删除用户余额记录
	@Modifying
	@Query("delete from UserAccount account where account.userId=:userid")
	void delUserAccount(@Param("userid") long userid);
}
